//
//  AppDelegate.swift
//  movieInfo
//
//  Created by zhangkai on 2023/5/7.
//

import UIKit
import GoogleMobileAds
import AppTrackingTransparency
import AdSupport
import SwiftyStoreKit
@main
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?
    

    func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?) -> Bool {
        // Override point for customization after application launch.
        
        
        
        
        
        SwiftyStoreKit.completeTransactions(atomically: true) { purchases in
            for purchase in purchases {
                if purchase.transaction.transactionState == .purchased || purchase.transaction.transactionState == .restored {
                    if purchase.needsFinishTransaction {
                  
                        SwiftyStoreKit.finishTransaction(purchase.transaction)
                    }
                    print("purchased: \(purchase)")
                }
            }
        }
        
        
        
        
        self.window = UIWindow()
        self.window?.backgroundColor = .white
        self.window?.frame = UIScreen.main.bounds
        self.window?.makeKeyAndVisible()
      
        window?.rootViewController = MMTabBarVC()
        
        
        GADMobileAds.sharedInstance().start(completionHandler: nil)
//        GADMobileAds.sharedInstance().requestConfiguration.testDeviceIdentifiers =
//            [ "2077ef9a63d2b398840261c8221a0c9b" ]
     
        
        
        return true
    }

    
    func applicationDidBecomeActive(_ application: UIApplication) {
        
        
        if #available(iOS 14, *) {
            switch ATTrackingManager.trackingAuthorizationStatus {
            case .denied:
                print("请打开IDFA权限")
                
            case .authorized:
                print("idfa:")
                
            case .notDetermined:
                DispatchQueue.main.asyncAfter(deadline: DispatchTime.now() + 1.5) {
                    ATTrackingManager.requestTrackingAuthorization { status in
                        if status == .authorized {
                            print("idfa:")
                        } else if status == .denied {
                            print("I")
                        }
                    }
                }
            default:
                break
            }
        } else {
            if ASIdentifierManager.shared().isAdvertisingTrackingEnabled {
                print("")
            } else {
                print("请打开IDFA权限")
            }
        }
        
    }


}

